package com.andy.blog.dal.service.impl;

import com.andy.blog.dal.domain.ArticleDO;
import com.andy.blog.dal.mapper.TArticleMapper;
import com.andy.blog.dal.service.TArticleDalService;
import com.andy.blog.dal.vo.TArticleVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by andy on 2023/6/17 12:06
 */
@Service
public class TArticleDalServiceImpl implements TArticleDalService {

    @Resource
    private TArticleMapper tArticleMapper;

    /**
     * 构建查询条件
     */
    private LambdaQueryWrapper<ArticleDO> buildQueryWrapper(TArticleVO tArticleVO) {
        LambdaQueryWrapper<ArticleDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        //lambdaQueryWrapper
        //        .eq(StringUtils.isNotBlank(dictTypeVO.getDictType()), SysDictTypeDO::getDictType, dictTypeVO.getDictType())
        //        .like(StringUtils.isNotBlank(dictTypeVO.getDictName()), SysDictTypeDO::getDictName, dictTypeVO.getDictName())
        //        .eq(StringUtils.isNotBlank(dictTypeVO.getStatus()), SysDictTypeDO::getStatus, dictTypeVO.getStatus())
        //        .ge(StringUtils.isNotBlank(dictTypeVO.getBeginTime()), SysDictTypeDO::getCreateTime, dictTypeVO.getBeginTime())
        //        .le(StringUtils.isNotBlank(dictTypeVO.getEndTime()), SysDictTypeDO::getCreateTime, dictTypeVO.getEndTime());
        return lambdaQueryWrapper;
    }

    @Override
    public IPage<ArticleDO> selectListByPage(TArticleVO tArticleVO) {
        LambdaQueryWrapper<ArticleDO> lambdaQueryWrapper = buildQueryWrapper(tArticleVO);

        IPage<ArticleDO> page = new Page<>(tArticleVO.getPageNum(), tArticleVO.getPageSize());

        return tArticleMapper.selectPage(page, lambdaQueryWrapper);
    }
}
